/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __DF35514D_582E_457a_BEF6_4FD10C6A32F0__
#define __DF35514D_582E_457a_BEF6_4FD10C6A32F0__

#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos
{
    // 
    // thread_impl
    // 
    class thread_impl : public xos_stl::mem_item< release_impl< thread_impl >, thread_lock >,
        public i_thread
    {
    public:
        typedef release_impl< thread_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_xos_item_data( ITEM_DATA*& item_ptr );

    public:
        thread_impl();
        ~thread_impl();

    protected:
        static DWORD WINAPI thread_proc( LPVOID lpData );
        int run();

        void * ( * m_thread_fun )( void * );
        HANDLE m_hThread;
        void * m_lpData;

    public:
        int init();
        int term();

    public:
        // 
        // create thread
        // 
        int create( void * ( * f )( void * ), void * lpData );

        // 
        // wait thread to terminate..
        // 
        int wait();
    };
} // xos

#endif // __DF35514D_582E_457a_BEF6_4FD10C6A32F0__
